package com.ruibang.glass.equipment.controller;


import com.ruibang.glass.equipment.constant.Constants;
import com.ruibang.glass.equipment.domain.req.device.DeviceAllPageReq;
import com.ruibang.glass.equipment.entity.device.PointCheckRecord;
import com.ruibang.glass.equipment.entity.device.ScrapReport;
import com.ruibang.glass.equipment.service.PointCheckRecordService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.seata.common.util.CollectionUtils;
import io.seata.common.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *点检记录
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@RestController
@RequestMapping("/api/equipment/point/check/record")
@Api(value = "点检记录")
public class PointCheckRecordController {
    @Autowired
    private PointCheckRecordService pointCheckRecordService;

    @PostMapping("list")
    @ApiOperation(value = "获取点检记录列表", response = ResultBody.class)
    public ResultBody getBoilerList(@RequestBody DeviceAllPageReq deviceAllPageReq) {
        return ResultBody.success(pointCheckRecordService.getPointRecordList(deviceAllPageReq));
    }

    @PostMapping("addOrUpdateCheck")
    @ApiOperation(value = "添加子层级", response = ResultBody.class)
    public ResultBody addChild(@RequestBody PointCheckRecord pointCheckPlan) {
        return ResultBody.success(pointCheckRecordService.addOrUpdateCheck(pointCheckPlan));
    }


    //
    @PostMapping("deleteAll")
    @ApiOperation(value = "添加子层级", response = ResultBody.class)
    public ResultBody deleteAll(@RequestBody PointCheckRecord pointCheckPlan) {
        if (!CollectionUtils.isEmpty(pointCheckPlan.getIds())) {
            pointCheckRecordService.lambdaUpdate().set(PointCheckRecord::getIsDelete, Constants.ONE_STR).in(PointCheckRecord::getId, pointCheckPlan.getIds()).update();
        }
        if (!StringUtils.isEmpty(pointCheckPlan.getId())) {
            pointCheckRecordService.lambdaUpdate().set(PointCheckRecord::getIsDelete, Constants.ONE_STR).eq(PointCheckRecord::getId, pointCheckPlan.getId()).update();
        }
        return ResultBody.success();
    }


    @PostMapping("getOne")
    @ApiOperation(value = "添加子层级", response = ResultBody.class)
    public ResultBody getOne(@RequestBody PointCheckRecord pointCheckPlan) {
        return ResultBody.success(pointCheckRecordService.getById(pointCheckPlan.getId()));
    }


    @PostMapping("deleteByIds")
    @ApiOperation(value = "添加子层级", response = ResultBody.class)
    public ResultBody deleteByIds(@RequestBody DeviceAllPageReq deviceAllPageRea) {
        return ResultBody.success(pointCheckRecordService.removeBatchByIds(deviceAllPageRea.getIds()));
    }




}
